<?php
class ContactController extends XPHP_Controller
{
	/**
	 * [[
	 * model: Areas_CP_Models_Contacts
	 * ]]
	 */
	public function indexAction()
	{
		$this->loadLayout("NewProduct");
		//Lấy thông tin website
		$model = new Areas_CP_Models_Settings();
		$this->view->settings = $model->select("id=1");
		
		$this->view->title = "Liên hệ với GMode";
		return $this->view();
	}
	/**
	 * [[
	 * model: Areas_CP_Models_Contacts
	 * ]]
	 */
	public function indexPOST()
	{
		if ($this->hasModel())
		{
			if ($this->model->isValid())
			{
				$this->model->date_create = XPHP_Date::toTime(date("H:i:s d/m/y"));
				$this->model->insert();
				//Gủi mail cho admin quản trị
				$mail = new XPHP_Mail();
				$subject = $this->model->fullname . ' gửi liên hệ ';
				$mail->content = $this->model->content;
				$mail->subject = $subject;
			
				$mail->toEmail = XPHP_Registry::get("config")->received->address;
				$mail->toName = XPHP_Registry::get("config")->received->name;
				
				$mail->send('gmail');
				
				return $this->redirect("sentSuccess");
			}
		}
	}
	
	public function sentSuccessAction()
	{
		//Lấy thông tin website
		$model = new Areas_CP_Models_Settings();
		$this->view->settings = $model->select("id=1");
		
		$this->loadLayout("NewProduct");
		return $this->view();
	}
}